package com.freecat.xmqgct.mvp.ui.holder;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.freecat.xmqgct.R;
import com.freecat.xmqgct.mvp.bean.RecordBean;
import com.freecat.xmqgct.mvp.bean.RecordChildBean;
import com.freecat.xmqgct.utils.SimpleRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：win
 * 时间：2019/10/9
 * 注释：
 */
public class RecordHolder {
    @BindView(R.id.tv_yw_dm)
    TextView tvYwDm;
    @BindView(R.id.tv_fc_sd)
    TextView tvFcSd;
    @BindView(R.id.tv_bhwms)
    TextView tvBhwms;
    @BindView(R.id.ll_dzbl)
    public LinearLayout llDzbl;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    private Context context;
    private OnChildClickListener listener;

    public RecordHolder(View view) {
        ButterKnife.bind(this, view);
        context = view.getContext();
    }

    public void setModel(RecordBean model) {
        tvYwDm.setText(model.getYwdm());
        tvFcSd.setText(model.getFcsd()+"m");
        tvBhwms.setText(model.getBhwms());
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new SimpleRecyclerAdapter<>(R.layout.item_record_child_layout, model.getChildBeans())
                .setOnBindViewListener((position, recordChildBean, view) -> {
                    RecordChildHolder holder = new RecordChildHolder(view);
                    holder.setModel(recordChildBean, position, model.getChildBeans().size());
                    holder.llQyjl.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (listener != null) {
                                listener.onChildClick(recordChildBean);
                            }
                        }
                    });
                }));
    }

    public interface OnChildClickListener {
        void onChildClick(RecordChildBean recordChildBean);
    }

    public void setOnChildClickListener(OnChildClickListener listener) {
        this.listener = listener;
    }
}
